﻿@inject IHttpService _httpService
@inject IDataCacheService _dataCacheService

@if (isReady)
{
    <div>
        @if (_dataCacheService.UserContentCenterCatche.UnReviewEntries.Any() == false && _dataCacheService.UserContentCenterCatche.UnReviewExamines.Any() == false && _dataCacheService.UserContentCenterCatche.PendingExamines.Any() == false && _dataCacheService.UserPendingDataCatche.Items.Any()==false)
        {
            <NotFoundCard Fill>
                <h1 class="text-center title-large">貌似没有待办事项，可以一起快乐摸鱼了呢</h1>
            </NotFoundCard>

        }

        <CnGalWebSite.Shared.MasaComponent.PC.EditRecords.UserCenter.ListUnReviewEntriesCard Model="_dataCacheService.UserContentCenterCatche.UnReviewEntries" />
        <CnGalWebSite.Shared.MasaComponent.PC.EditRecords.UserCenter.ListUnReviewEditRecordsCard Model="_dataCacheService.UserContentCenterCatche.UnReviewExamines" />
        <CnGalWebSite.Shared.MasaComponent.PC.EditRecords.UserCenter.ListPendingExaminesCard Model="_dataCacheService.UserContentCenterCatche.PendingExamines" />
        <CnGalWebSite.Shared.MasaComponent.PC.Users.Examines.PendingDataCard Model="_dataCacheService.UserPendingDataCatche.Items" />
    </div>
}
else
{
    <CnGalWebSite.Components.Progressings.ProgressingCard Page Fill />
}



@code {

    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }


    bool isReady;

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            try
            {
                if (_dataCacheService.UserContentCenterCatche == null)
                {
                    _dataCacheService.UserContentCenterCatche = await _httpService.GetAsync<UserContentCenterViewModel>("api/examines/GetUserContentCenterView");
                }
                if (_dataCacheService.UserPendingDataCatche.Items.Any() == false)
                {
                    _dataCacheService.UserPendingDataCatche.Items = (await _httpService.GetAsync<List<UserPendingDataModel>>("api/space/GetUserPendingData")).OrderByDescending(s => s.DisplayMode).ToList();
                }

                isReady = true;
                StateHasChanged();
            }
            catch (Exception ex)
            {
                await ErrorHandler.ProcessError(ex, "无法获取内容中心视图数据");
            }
        }
    }
}

